package pierre_feuille_ciseaux;

import java.util.ArrayList;
import java.util.List;

import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;


public class TestRockPapersScissors {
	
	private static RockPaperScissors rps;
	private static List<RPSEnum> moves;
	private static List<RPSEnum> moves2;
	
	
	@BeforeClass public static void setUpClass(){
		rps = new RockPaperScissors();
		moves= new ArrayList<RPSEnum>();
		moves2 = new ArrayList<RPSEnum>();
		for(int i=0;i<10;i++){
		moves.add(RPSEnum.ROCK);
		moves2.add(RPSEnum.SCISSOR);
		}
	}
	
	@Test public void testWinPlay(){
		RPSEnum p1 = RPSEnum.ROCK;
		RPSEnum p2 = RPSEnum.SCISSOR;
		Result result = rps.ResultPlay(p1, p2);
		Assert.assertEquals(result,Result.WIN);
	}
	
	@Test public void testTiePlay(){
		RPSEnum p1 = RPSEnum.ROCK;
		RPSEnum p2 = RPSEnum.ROCK;
		Result result = rps.ResultPlay(p1, p2);
		Assert.assertEquals(result,Result.TIE);
	}
	
	@Test public void testLostPlay(){
		RPSEnum p1 = RPSEnum.ROCK;
		RPSEnum p2 = RPSEnum.PAPER;
		Result result = rps.ResultPlay(p1, p2);
		Assert.assertEquals(result,Result.LOST);
	}
	
	@DataProvider(name = "test1") public static Object[][] CreateWinData(){
		return new Object[][] { {RPSEnum.ROCK, RPSEnum.SCISSOR}, {RPSEnum.SCISSOR,RPSEnum.PAPER}, {RPSEnum.PAPER,RPSEnum.ROCK}};
	}
	
	@DataProvider(name = "test2") public static Object[][] CreateLostData(){
		return new Object[][] { {RPSEnum.ROCK, RPSEnum.PAPER}, {RPSEnum.SCISSOR,RPSEnum.ROCK}, {RPSEnum.PAPER,RPSEnum.SCISSOR}};
	}
	
	@DataProvider(name = "test3") public static Object[][] CreateTieData(){
		return new Object[][] { {RPSEnum.ROCK, RPSEnum.ROCK}, {RPSEnum.SCISSOR,RPSEnum.SCISSOR}, {RPSEnum.PAPER,RPSEnum.PAPER}};
	}
	
	@Test(dataProvider = "test1") public void testWinPlay2(RPSEnum p1, RPSEnum p2){
		Result result = rps.ResultPlay(p1, p2);
		Assert.assertEquals(result,Result.WIN);
	}
	
	@Test(dataProvider = "test2") public void testLostPlay2(RPSEnum p1, RPSEnum p2){
		Result result = rps.ResultPlay(p1, p2);
		Assert.assertEquals(result,Result.LOST);
	}
	
	@Test(dataProvider = "test3") public void testTiePlay2(RPSEnum p1, RPSEnum p2){
		Result result = rps.ResultPlay(p1, p2);
		Assert.assertEquals(result,Result.TIE);
	}
	
	@Test public void gameTieTest(){
		Player p1 = new Player("p1",moves);
		Player p2 = new Player("p2",moves);
		Result result = rps.play(p1, p2);
		Assert.assertEquals(result, Result.TIE);
	}
	
	@Test public void gameWinTest(){
		Player p1 = new Player("p1",moves);
		Player p2 = new Player("p2",moves2);
		Result result = rps.play(p1, p2);
		Assert.assertEquals(result, Result.WIN);
	}
	
	@Test public void gameLostTest(){
		Player p1 = new Player("p1",moves2);
		Player p2 = new Player("p2",moves);
		Result result = rps.play(p1, p2);
		Assert.assertEquals(result, Result.LOST);
	}
	
	@AfterClass
	public void tearDownClass(){
		rps=null;
		moves=null;
		moves2=null;
	}
}
